package com.sxp.service;

import com.sxp.dao.FoodSelectionDaoImpl;
import com.sxp.dao.MealDaoImpl;
import com.sxp.dao.RiceDaoImpl;
import com.sxp.model.FoodSelection;
import com.sxp.model.MealType;
import com.sxp.model.Month;
import com.sxp.model.RiceType;

import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by dinethri on 10/16/14.
 */
public class FoodSelectionService {
    private final FoodSelectionDaoImpl fdsdaoImpl;
    private final MealDaoImpl mealImpl;
    private final RiceDaoImpl riceImpl;
    private final Month gcd;

    public FoodSelectionService() {
        fdsdaoImpl=new FoodSelectionDaoImpl();
        mealImpl=new MealDaoImpl();
        riceImpl=new RiceDaoImpl();
        gcd=new Month();
    }

    public List<FoodSelection> curFoodSelDao(){
        List<FoodSelection> fdS=fdsdaoImpl.getFoodSelection();

        return fdS;
    }

    public List<FoodSelection> callDaoForDate(String date) throws ParseException, SQLException {
        String dateS=date;
        List<FoodSelection> fdSDate=fdsdaoImpl.getAllFoodSForDate(dateS);
        return fdSDate;
    }

    public List<MealType> getAllMealList(){
        List<MealType> mealList=mealImpl.getMealList();
        return mealList;
    }

    public List<RiceType> getAllRiceList() {
        List<RiceType> riceList=riceImpl.getRiceList();
        return riceList;
    }

    public void updateSel(FoodSelection fds){
        FoodSelection fdsel=fds;
        fdsdaoImpl.updateSelection(fdsel);

    }

    public FoodSelection getFoodSelectionByNameDate(String username,String date) throws ParseException {
        String editingUser=username;
        String editDate=date;
        FoodSelection fs= (FoodSelection) fdsdaoImpl.getFoodSelectionByName(editingUser, editDate);
        return fs;
    }

    public FoodSelection getFoodSByNameOnly(String username) {
        String user=username;
        FoodSelection fsItem=fdsdaoImpl.getFoodSOnlByName(user);
        return fsItem;
    }


    public Date chkDate(String urlD) throws ParseException {
        String urlDate=urlD;
        DateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date urld=sd.parse(urlDate);

        return urld;
    }

    public String getCurntDate(){
        String currDate=gcd.curD();
        return currDate;
    }
}
